<template>
	<view class="add-contract-box" :style="'padding-top:'+(barHeight)+'px'">
		<NavBar>
			<template v-slot:center>
				<view class="nav_center">
					{{type==1?'新增销售合同':'新增采购合同'}}
				</view>
			</template>
			<template v-slot:left>
				<text class="cancel-add" @click="cancelAdd">取消</text>
			</template>
		</NavBar>
		<view class="" v-if="tab==0">
			<AddContractBaseInfo :flag="type" :id="id"></AddContractBaseInfo>
		</view>
		<view class="" v-if="tab==1">
			<ProcureList :contractId="id" :flag="0"></ProcureList>
		</view>
		<view class="" v-if="tab==2">
			<UploadAnnex :relationId="id" :type="type"></UploadAnnex>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import AddContractBaseInfo from './AddContractBaseInfo.vue'
	import UploadAnnex from '@/components/UploadAnnex.vue'
	import ProcureList from './ProcureList.vue'
	import {
		api,
		post
	} from '@/util/api.js'
	export default {
		components: {
			NavBar,
			AddContractBaseInfo,
			UploadAnnex,
			ProcureList
		},
		data() {
			return {
				tab: 0, // 模拟选项卡页面
				id: '', // 合同Id
				type: 0 ,// 1销售合同，2采购合同
				barHeight: 0,
			}
		},
		onLoad(option) {
			this.type = option.type
			this.id = option.id
		},
		created() {
			this.barHeight = uni.getSystemInfoSync().statusBarHeight + 45 + 10;
		},
		beforeMount() {
			uni.$on('changeTab', (tab, contractId) => {
				this.tab = tab
				if (contractId) {
					this.id = contractId
				}
			})
			// 点击确认后返回列表界面
			uni.$on('saveBack', (type) => {
				if (type == 1) {
					uni.$emit('reloadSaleContractList')
				} else if (type == 2) {
					uni.$emit('reloadProcureContractList')
				}
			})
		},
		beforeDestroy() {
			uni.$off('changeTab');
			uni.$off('saveBack');
		},
		methods: {
			cancelAdd() {
				if (this.type == 1) {
					uni.$emit('reloadSaleContractList')
				} else if (this.type == 2) {
					uni.$emit('reloadProcureContractList')
				}
			},
		}
	}
</script>

<style>
	@import '../../static/css/AddContract.css';
	@import '../../static/css/commons.css';
</style>
